package pp.gateway.domain.user.aggregation.repository;

import lombok.extern.slf4j.Slf4j;
import pp.gateway.domain.user.aggregation.entity.loginstrategy.AccountLoginStrategy;
import pp.gateway.domain.user.aggregation.entity.loginstrategy.TelephoneMsgLoginStrategy;
import pp.infrastructure.mysql.mapper.user.UserReader;
import pp.infrastructure.util.SpringBeanHolder;

@Slf4j
public class UserLogin {

    private final Long userId;
    private AccountLoginStrategy accountLoginStrategy;
    private TelephoneMsgLoginStrategy telephoneMsgLoginStrategy;

    private UserReader userReader;

    public UserLogin(Long userId) {
        this.userId = userId;
        init();
    }

    private void init() {
        this.userReader = SpringBeanHolder.getBean(UserReader.class);
    }

    public boolean loginWithPassword(String password) {
        return getAccountLoginStrategy().verifyPwd(password);
    }

    public Long getUserId() {
        return userId;
    }

    public AccountLoginStrategy getAccountLoginStrategy() {
        return accountLoginStrategy;
    }

    public void setAccountLoginStrategy(AccountLoginStrategy accountLoginStrategy) {
        this.accountLoginStrategy = accountLoginStrategy;
    }

    public TelephoneMsgLoginStrategy getTelephoneMsgLoginStrategy() {
        return telephoneMsgLoginStrategy;
    }

    public void setTelephoneMsgLoginStrategy(TelephoneMsgLoginStrategy telephoneMsgLoginStrategy) {
        this.telephoneMsgLoginStrategy = telephoneMsgLoginStrategy;
    }
}
